import 'package:unt/tt_entity.dart';

ttEntityFromJson(TtEntity data, Map<String, dynamic> json) {
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['num'] != null) {
		data.num = json['num'] is String
				? int.tryParse(json['num'])
				: json['num'].toInt();
	}
	if (json['sites'] != null) {
		data.sites = (json['sites'] as List).map((v) => TtSites().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> ttEntityToJson(TtEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['name'] = entity.name;
	data['num'] = entity.num;
	data['sites'] =  entity.sites?.map((v) => v.toJson())?.toList();
	return data;
}

ttSitesFromJson(TtSites data, Map<String, dynamic> json) {
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['info'] != null) {
		data.info = (json['info'] as List).map((v) => v.toString()).toList().cast<String>();
	}
	return data;
}

Map<String, dynamic> ttSitesToJson(TtSites entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['name'] = entity.name;
	data['info'] = entity.info;
	return data;
}